﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Betop.Lib.Core.Base;

namespace Betop.Lib.Core.User
{
    public class OnlineUserDAL : BaseDAL
    {
        internal List<OnlineUserInfo> GetOnlineUserList(DateTime begin)
        {
            string sql = "select * from OnlineUser where LastVisitTime > @p0";
            return dbOper.Query<OnlineUserInfo>(sql, begin);
        }

        internal List<int> GetOnlineUserIDs(DateTime begin)
        {
            string sql = "select ID from OnlineUser where LastVisitTime > @p0";
            return dbOper.Query<int>(sql, begin);
        }

        internal int GetUserID(string strIP)
        {
            string sql = "select ID from OnlineUser where IP=@p0 order by LastVisitTime desc";//有可能一个ip出现两个用户登录过
            return dbOper.Query<int>(sql, strIP).First();
        }

        internal string GetUserIP(int userID)
        {
            string sql = "select IP from OnlineUser where ID=@p0";
            List<string> ips = dbOper.Query<string>(sql, userID);
            return (ips.Count > 0) ? ips.First() : null;
        }
    }

}
